package main

import "C"
import (
	"fmt"
	"math/rand"
	"time"
)

func main1() {
	var ret uintptr
	var err error

	ret, err = InitLed(0, 0)
	if err != nil {
		println(err.Error())
	} else {
		if ret != 0 {
			println("=====InitLed ERR=======")
			GetError(ret)
		}
	}
	ret, err = RefreshNeiMaArea(
		"192.168.124.99",
		"%disp2:0neia测试123456")
	if err != nil {
		println(err.Error())
	} else {
		if ret != 0 {
			println("=====RefreshNeiMaArea ERR=======")
			GetError(ret)
		}
	}
}

func main() {
	var ret uintptr
	ret, err := InitLed(0, 0)
	if err != nil {
		println(err.Error())
	} else {
		if ret != 0 {
			println("=====InitLed ERR=======")
			GetError(ret)
		}
	}
	hd, err := CreateProgram(128, 32, 2, 0, 0)
	if err != nil {
		println(err.Error())
	} else {
		if hd != 0 {
			println("=====CreateProgram ERR=======")
			GetError(hd)
		} else {
			println("=====AddProgram Success=======")
		}
	}
	//添加节目
	ret, err = AddProgram(hd, 0, 0, 1)
	if err != nil {
		println(err.Error())
	} else {
		if ret != 0 {
			println("=====AddProgram ERR=======")
			GetError(ret)
		} else {
			println("=====AddProgram Success=======")
		}
	}
	//p1(hd)
	//添加一个内码区域
	pAreaRect1 := &AREARECT{
		Left:   0,
		Top:    0,
		Width:  128,
		Height: 16,
	}
	pAreaRect2 := &AREARECT{
		Left:   0,
		Top:    16,
		Width:  128,
		Height: 16,
	}
	PlayProp := &PLAYPROP{
		InStyle:   0,
		OutStyle:  0,
		Speed:     10,
		DelayTime: 10,
	}
	ret, err = AddNeiMaArea(hd, 0, 2,
		"AABBCC", 16, 0xff,
		pAreaRect2, PlayProp)
	if err != nil {
		println(err.Error())
	} else {
		if ret != 0 {
			println("=====AddNeiMaArea ERR=======")
			GetError(ret)
		} else {
			println("=====AddNeiMaArea Success=======")
		}
	}
	ret, err = AddNeiMaArea(hd, 0, 3,
		"AABBCC", 16, 0xff,
		pAreaRect1, PlayProp)
	if err != nil {
		println(err.Error())
	} else {
		if ret != 0 {
			println("=====AddNeiMaArea ERR=======")
			GetError(ret)
		} else {
			println("=====AddNeiMaArea Success=======")
		}
	}

	ret, err = Send("192.168.124.99", hd)
	if err != nil {
		println(err.Error())
	} else {
		if ret != 0 {
			println("=====Send ERR=======")
			GetError(ret)
		} else {
			println("=====Send Success=======")
		}
	}

	for {
		time.Sleep(100 * time.Millisecond)
		neiMaStr := "%disp0:0" + fmt.Sprintf("A发发发11%d", rand.Intn(999))
		neiMaStr += "%disp1:0" + fmt.Sprintf("B发发发11%d", rand.Intn(999))
		ret, err = RefreshNeiMaArea(
			"192.168.124.99",
			neiMaStr)
		if err != nil {
			println(err.Error())
		} else {
			if ret != 0 {
				println("=====RefreshNeiMaArea ERR=======")
				GetError(ret)
			} else {
				println("=====RefreshNeiMaArea Success=======")
			}
		}
	}

	//StringToInt32("192.168.124.99")
	//ret, err = PowerOnOff("192.168.124.99", 0)
	//
	//println("PowerOnOff RET=", ret)
	//if ret != 0 {
	//	println("=====PowerOnOff ERR=======")
	//	GetError(ret)
	//}
}

func p1(hd uintptr) {
	var ret uintptr
	//添加一个图文区域
	pAreaRect := AREARECT{
		Top:    0,
		Width:  64,
		Height: 32,
		Left:   0,
	}
	ret, err := AddImageTextArea(hd, 0, 1, &pAreaRect, 1)
	if err != nil {
		println(err.Error())
	} else {
		if ret != 0 {
			println("=====AddImageTextArea ERR=======")
			GetError(ret)
		}
	}
	fontProp := FONTPROP{
		FontColor:     0xffffff,
		FontSize:      6,
		FontBold:      0,
		FontItalic:    0,
		FontUnderLine: 0,
	}
	ret, err = AddStaticTextToImageTextArea(hd, 0, 1,
		0, fmt.Sprintf("192.168.124.99.%d", rand.Intn(999)), &fontProp, 100, 0, 0)
	if err != nil {
		println(err.Error())
	} else {
		if ret != 0 {
			println("=====AddStaticTextToImageTextArea ERR=======")
			GetError(ret)
		}
	}
}
